﻿namespace Services
{
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using ClientProxies;
  using ClientProxies.OneStepServiceReference;
  using Exceptions;
  using ServiceInterfaces;

  public class OneStepService : IOneStepService
  {
      private IServiceFactory _factory;

      public OneStepService(IServiceFactory factory)
      {
          this._factory = factory;
      }

    public List<FileStatusData> GetFileData(DateTime syncDate, String companyCode)
    {
      try
      {
        //IServiceFactory _factory; 
          IFileService proxy = _factory.CreateFileServiceClient<IFileService>();

        return proxy.GetFileStatusInfo(syncDate, companyCode)
               .Where(t => Path.GetExtension(t.FileName) == ".xml")
               .ToList();
      }
      catch (Exception e)
      {
        throw new UnityException("Unable to retrieve one step data", e);
      }
    }
  }
}

